<?php 
$data['page_selected'] = 'home';
$this->load->view('constants/header', $data);?>

<div id="site_content">
	<?php $this->load->view('constants/sidebar'); ?> 
    <div id="content">
        <br /><br /><br /><br />
        <h1>Editar perfil</h1>

<script type="text/javascript">
	$(document).ready(function() {
		$.datepicker.regional['es'] = {
		closeText: 'Cerrar',
		prevText: '&#x3c;Ant',
		nextText: 'Sig&#x3e;',
		currentText: 'Hoy',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
		'Jul','Ago','Sep','Oct','Nov','Dic'],
		dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
		dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
		dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
		weekHeader: 'Sm',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['es']);
		
		$("#birthdate").datepicker({
			dateFormat: 'dd/mm/yy',
			changeMonth: true,
			changeYear: true,
			minDate: "-50Y", 
			maxDate: "+0"
			});
		
	});
	
	$(function() {
		var availableTags = new Array();
		<?php for($i=0; $i <  count($buddies) ; $i++){?>
			availableTags[<?php echo($i); ?>] = {label: "<?php echo($buddies[$i]['nombre'].' '.$buddies[$i]['apellido'].', CI:'.$buddies[$i]['ci_integrante']);?>",
												 value: "<?php echo($buddies[$i]['id_integrante']);?>"};
		<?php } ?>	
		
		$('#tags').autocomplete({
			minLength: 2,
			source: availableTags,
			focus: function(event, ui) {
				$('#tags').val(ui.item.label);
				return false;
			},
			select: function(event, ui) {
				$('#tags').val(ui.item.label);
				$('#id_buddy').val(ui.item.value);				
				return false;
			}
		});
	});
</script>
	<?php echo form_open(base_url().'user/edit_profile');?>
        	<h2 style="font-size:10px"><img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp; Campos Obligatorios</h2>
            <table>
            	<tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Nombre </td>
                    <td> <input type="text" name="name" id="name" value="<?php echo $user['nombre']; ?>"/> </td>
                    <td> <?php echo form_error('name'); ?> </td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Apellido </td>
                    <td> <input type="text" name="lastname" id="lastname" value="<?php echo $user['apellido']; ?>"/> </td>
                    <td> <?php echo form_error('lastname'); ?> </td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;C.I. </td>
                    <td> <input type="text" name="ci" id="ci" value="<?php echo $user['ci_integrante']; ?>"/> </td>
                    <td> <?php echo form_error('ci'); ?> </td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;G&eacute;nero </td>
                    <td> 
                    	<?php if($user['genero'] == 'm'){ ?>
                    		<input type="radio" name="genre" id="genre" value="m" checked="checked"/>M &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                    		<input type="radio" name="genre" id="genre" value="f"/>F 
                        <?php } 
						else{?>
                        	<input type="radio" name="genre" id="genre" value="m"/>M &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                    		<input type="radio" name="genre" id="genre" value="f" checked="checked"/>F 
                        <?php } ?>
                    </td>
                    <td></td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Fecha de Nacimiento </td>
                    <td> <input type="text" name="birthdate" id="birthdate" readonly="readonly" value="<?php echo format_date($user['fecha_nacimiento']); ?>"/> </td>
                    <td> <?php echo form_error('birthdate'); ?> </td>
                </tr>
                <tr>
                	<td> Tipo de discapacidad </td>
                    <td> 
                    	<select name="disability" id="disability"> 
                        	<?php if($user['COD_DISCAPACIDAD'] == NULL) {?>
                        		<option value="-" selected>N/A</option>
                        	<?php } else { ?>
                            	<option value="-">N/A</option>
                            <?php }
							foreach($disabilities as $d){ 
								if($d['cod_discapacidad'] == $user['COD_DISCAPACIDAD']){ ?>
                                    <option value="<?php echo $d['cod_discapacidad'] ?>" selected>
                                        <?php echo $d['descripcion']; ?>
                                    </option>
                                <?php } else {?>
                                	<option value="<?php echo $d['cod_discapacidad'] ?>">
                                        <?php echo $d['descripcion']; ?>
                                    </option>
                            <?php } 
							}?>
                        </select>
                    </td>
                    <td></td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Tipo de Buddy </td>
                    <td> 
                    	<select name="buddy_type" id="buddy_type"> 
                        	<option value="-">-----</option>
                        	<?php foreach($buddy_types as $b){ 
									if($user['COD_TIPO_BUDDY'] == $b['cod_tipo_buddy']){ ?>
                                        <option value="<?php echo $b['cod_tipo_buddy'] ?>" selected>
                                            <?php echo $b['descripcion']; ?>
                                        </option>
                                    <?php } else { ?>
                                    	<option value="<?php echo $b['cod_tipo_buddy'] ?>">
                                            <?php echo $b['descripcion']; ?>
                                        </option>
                            <?php } 
							}?>
                        </select>
                    </td>
                    <td> <?php echo form_error('buddy_type'); ?> </td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Club perteneciente </td>
                    <td> 
                    	<select name="id_club" id="id_club"> 
                        	<option value="-">-----------</option>
                        	<?php foreach($clubs as $c){ 
									if($user['ID_CLUB'] == $c['id_club']){?>
                                        <option value="<?php echo $c['id_club'] ?>" selected>
                                            <?php echo $c['nombre']; ?>
                                        </option>
                                    <?php } else { ?>
                                    	<option value="<?php echo $c['id_club'] ?>">
                                            <?php echo $c['nombre']; ?>
                                        </option>
                            <?php } 
							}?>
                        </select>
                    </td>
                    <td> <?php echo form_error('id_club'); ?> </td>
                </tr>
                <tr>
                	<td> Buddy asignado </td>
                    <td> 
                    	<input id="tags" value="<?php echo $user['BEST_BUDDY'] ?>"/> 
	                    <input type="hidden" name="id_buddy" id="id_buddy" value="<?php echo $user['ID_BEST_BUDDY'] ?>"/> </td>
                    <td></td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Tel&eacute;fono Celular </td>
                    <td> <input type="text" name="celphone" id="celphone" value="<?php echo $user['telefono_celular']; ?>"/> </td>
                    <td> <?php echo form_error('celphone'); ?> </td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Tel&eacute;fono de Habitaci&oacute;n </td>
                    <td> <input type="text" name="phone" id="phone" value="<?php echo $user['telefono_habitacion']; ?>"/> </td>
                    <td> <?php echo form_error('phone'); ?> </td>
                </tr>
                <tr>
                	<td rowspan="7"> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Direcci&oacute;n </td>
                    <td> 
                    	<textarea name="address" id="address" cols="17" rows="6"><?php echo $user['direccion']; ?></textarea>
                    </td>
                    <td>
                    	<?php echo form_error('address'); ?> 
                    </td>
                </tr>
                <tr>
                	<td>                        
                        <div class="formField" id="coS">
                        	<span class="InputValue" >
								<?php if ($user['pais'] == "") {?> 
                                	Pa&iacute;s
                                <?php } ?>
                            </span>
                            <input type="text" name="country" id="country" onfocus="onFocusInput('co')" onblur="onBlurInput('country','co', 'Pa&iacute;s')" value="<?php echo $user['pais']; ?>" /> 
                        </div>
                    </td>
                    <td>
                    	<?php echo form_error('country'); ?>
                    </td>
                </tr>
                <tr>
                	<td>
                        <div class="formField" id="stS"> 
                        	<span class="InputValue" >
                            	<?php if ($user['estado'] == "") {?> 
                                	Estado
                                <?php } ?>
                            </span>
                            <input type="text" name="state" id="state" onfocus="onFocusInput('st')" onblur="onBlurInput('state','st', 'Estado')" value="<?php echo $user['estado']; ?>"/> 
                        </div>
                   	</td>
                    <td>
                    	<?php echo form_error('state'); ?>
                    </td>
                </tr>
                <tr>
                	<td>
                        <div class="formField" id="muS">
                        	<span class="InputValue">
                            	<?php if ($user['municipio'] == "") {?> 
                                	Municipio
                                <?php } ?>
                            </span>
                            <input type="text" name="municipality" id="municipality" onfocus="onFocusInput('mu')" onblur="onBlurInput('municipality','mu', 'Municipio')" value="<?php echo $user['municipio']; ?>"/>
                        </div>
                        </td>
                    <td>
                    	<?php echo form_error('municipality'); ?>
                    </td>
                </tr>
                <tr>
                	<td>
                        <div class="formField" id="paS"> 
                        	<span class="InputValue">
                            	<?php if ($user['parroquia'] == "") {?> 
                                	Parroquia
                                <?php } ?>
                            </span>
                            <input type="text" name="parish" id="parish" onfocus="onFocusInput('pa')" onblur="onBlurInput('parish','pa', 'Parroquia')" value="<?php echo $user['parroquia']; ?>"/>
                        </div>
                        </td>
                    <td>
                    	<?php echo form_error('parish'); ?>
                    </td>
                </tr>
                <tr>
                	<td>
                        <div class="formField" id="avS"> 
                        	<span class="InputValue">
                            	<?php if ($user['avenida'] == "") {?> 
                                	Avenida
                                <?php } ?>
                            </span>
                            <input type="text" name="avenue" id="avenue" onfocus="onFocusInput('av')" onblur="onBlurInput('avenue','av', 'Avenida')" value="<?php echo $user['avenida']; ?>"/>
                        </div>
                        </td>
                    <td>
                    	<?php echo form_error('avenue'); ?>
                    </td>
                </tr>
                <tr>
                	<td>
                        <div class="formField" id="strS"> 
                        	<span class="InputValue">
                            	<?php if ($user['calle'] == "") {?> 
                                	Calle
                                <?php } ?>
                            </span>
                            <input type="text" name="street" id="street" onfocus="onFocusInput('str')" onblur="onBlurInput('street','str', 'Calle')" value="<?php echo $user['calle']; ?>"/>
                        </div>
                        </td>
                    <td>
                    	<?php echo form_error('street'); ?>
                    </td>
                </tr>
                <tr>
                	<td> <img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp;Direcci&oacute;n de correo electr&oacute;nico </td>
                    <td> <input type="text" name="email" id="email" value="<?php echo $user['email']; ?>"/> </td>
                    <td> <?php echo form_error('email'); ?> </td>
                </tr>
                <tr>
                	<td> Seud&oacute;nimo de Twitter </td>
                    <td> <input type="text" name="twitter" id="twitter" value="<?php echo $user['twitter']; ?>"/> </td>
                    <td> <?php echo form_error('twitter'); ?> </td>
                </tr>
                <tr>
                	<td> Facebook </td>
                    <td> <input type="text" name="facebook" id="facebook" value="<?php echo $user['facebook']; ?>"/> </td>
                    <td> <?php echo form_error('facebook'); ?> </td>
                </tr>
                <tr>
                	<td> P&aacute;gina Web </td>
                    <td> <input type="text" name="webpage" id="webpage" value="<?php echo $user['pag_web']; ?>"/> </td>
                    <td> <?php echo form_error('webpage'); ?> </td>
                </tr>
                
                <tr>
                	<td colspan="3" align="right">
                    	<input type="submit" name="button" class="submit" value="Procesar" />
                    </td>
                </tr>
            </table>
            <h2 style="font-size:10px"><img src="<?php echo base_url().IMG; ?>icon_RequiredField.png">&nbsp; Campos Obligatorios</h2>
            
            
        </form>

    </div>
</div>
<script type="text/javascript">	
	function onFocusInput(divId){
		$('#'+divId+'S span').html("");
	}
	
	function onBlurInput(inputId, divId, value){
		if($('#'+inputId+'').val() == "")
			$('#'+divId+'S span').html(value);
		else
			$('#'+divId+'S span').html("");
	}
</script>
<?php $this->load->view('constants/footer'); ?>
